
// Copyright (C) Recursion Company. All rights reserved.

#ifndef __VOL_WTL_RICH_EDIT_H__
#define __VOL_WTL_RICH_EDIT_H__

class IRichEditEventListener : public IBaseEventListener
{
public:
    virtual void OnChange () = 0;
    virtual void OnSelChange () = 0;
};

class CVWnd_RichEdit : public CWindowImpl<CVWnd_RichEdit, CRichEditCtrl>
{
    BEGIN_DECLARE_VOL_NATIVE_WND_CLASS (CVWnd_RichEdit, IRichEditEventListener, TRUE)
	    REFLECTED_COMMAND_CODE_HANDLER_EX (EN_CHANGE, OnChange)
	    REFLECTED_COMMAND_CODE_HANDLER_EX (EN_KILLFOCUS, OnKillfocus)
	    REFLECTED_COMMAND_CODE_HANDLER_EX (EN_SETFOCUS, OnSetfocus)
	    REFLECTED_NOTIFY_CODE_HANDLER_EX (EN_PROTECTED, OnProtected)
	    REFLECTED_NOTIFY_CODE_HANDLER_EX (EN_SELCHANGE, OnSelChange)
    END_DECLARE_VOL_NATIVE_WND_CLASS_NOT_CONTAINER ()
    DECLARE_WND_SUPERCLASS (NULL, CRichEditCtrl::GetWndClassName ())

public:
    CVWnd_RichEdit ();

    inline_ ~CVWnd_RichEdit ()
    {
        if (m_hInstRichEdit != NULL)
            ::FreeLibrary (m_hInstRichEdit);
    }

protected:
    LRESULT OnChange (UINT uNotifyCode, int nID, CWindow wndCtl);
    LRESULT OnKillfocus (UINT uNotifyCode, int nID, CWindow wndCtl);
    LRESULT OnSetfocus (UINT uNotifyCode, int nID, CWindow wndCtl);
    LRESULT OnProtected (LPNMHDR pNMHDR);
    LRESULT OnSelChange (LPNMHDR pNMHDR);

public:
    void SetContent (const TCHAR* szContent, BOOL blOnlySelection);
    void GetContent (CVolString& strContent, BOOL blOnlySelection);
    void SetRichEditSel (INT nSelStart, INT nSelLength);
	inline_ void LimitRichEditText (INT nChars)
    {
	    LimitText (nChars <= 0 ? INT_MAX : nChars);
    }

public:
    BOOL m_blPlainTextMode;
    INT m_nContentType;
    INT m_nBorderType;
    COLORREF m_clrBackColor;
    BOOL m_blMutiLine;
    BOOL m_blAutoNextLine;
    BOOL m_blReadOnly;
    BOOL m_blHideSelection;
    INT m_nMaxAllowLength;
    INT m_nSelStart;
    INT m_nSelLength;

protected:
    BOOL m_blModifingProperty;
    HINSTANCE m_hInstRichEdit;
};

#endif
